package com.practice.graph;

import java.util.PriorityQueue;

public class FindKthCompound {
	public long find(int p, int q, int r, int k) {
		PriorityQueue<Long> pq = new PriorityQueue<Long>();
		long t = 1;
		pq.add(t);
		for (int i=0; i<k; i++) {
			t = pq.remove();
			add(pq, p*t);
			add(pq, q*t);
			add(pq, r*t);
		}
		return t;
	}
	
	private void add(PriorityQueue<Long> pq, long n) {
		if (!pq.contains(n)) pq.add(n);
	}
	
	public static void main(String[] args) {
		System.out.println(new FindKthCompound().find(2, 3, 5, 10000));
	}
}
